
x=100;
U=1;
h=50;
dx=1;
g=9.81;
dx1=1/dx;
dx2=1/dx/dx;
dt=1/(2*sqrt(g*h))
% Schur with Central Discretization


A(1,x) = -U*0.5*dx1;
A(1,2) =  U*0.5*dx1;
for k=2:x-1
    A(k,k-1) = -U*0.5*dx1;
    A(k,k+1) =  U*0.5*dx1;
end

A(x,x-1) = -U*0.5*(1/dx);
A(x,1)   =  U*0.5*(1/dx);

for i=1:x
    A(i,i)=1/dt+0.5*A(i,i);
end

B=zeros(x,x);

B(1,x)=h*dx2;
B(1,2)=h*dx2;
B(1,1)=-2*h*dx2;
for k=2:x-1
    B(k,k)= -2*h*dx2; 
    B(k,k-1)=h*dx2;
    B(k,k+1)=h*dx2;
end
B(x,1)=h*dx2;
B(x,x-1)=h*dx2;
B(x,x)=-2*h*dx2;

C = g*eye(x,x);


L = zeros(2*x,2*x);
L(1:x,1:x)=A;
L(x+1:2*x,x+1:2*x)=A;
%L(1:x,x+1:2*x)=B;
%L(x+1:2*x,1:x)=C;

e3=eig(L);

S = A - B*inv(A)*C;

e1= eig(S);

e2 = eig(A);

    
e(:,1)=e1;
e(:,2)=e2;
%e(:,3)=e3;
k1 = cond(B)
k2 = cond(C)
k3 = cond(A)
k4 = cond(L)
k5 = cond(S)

% % Schur with Upwinding
% 
% A1 = zeros(x,x);
% A1(1,1) = -U*dx1;
% A1(1,2) =  U*dx1;
% for k=2:x-1
%     A1(k,k) = -U*dx1;
%     A1(k,k+1) =  U*dx1;
% end
% 
% A1(x,x) = -U*dx1;
% A1(x,1)   =  U*(dx1);
% 
% for i=1:x
%     A1(i,i)=1+0.5*A1(i,i);
% end
% 
% L1 = zeros(2*x,2*x);
% L1(1:x,1:x)=A1;
% L1(x+1:2*x,x+1:2*x)=A1;
% L1(1:x,x+1:2*x)=B;
% L1(x+1:2*x,1:x)=C;
% 
% 
% k1 = cond(L1)
% k2 = cond(A1 - B*inv(A1)*C)
% k3 = cond(A1)